<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>flex&margin组合布局</title>
    <style>
      .container {
        display: flex;
        flex-flow: row wrap;
        width: 500px;
        /* height: 500px; */
        padding: 10px;
        margin: 50px auto;
        background-color: #bfa;
      }
      .box {
        width: 20px;
        height: 20px;
        /* 水平垂直居中 */
        /* margin: auto; */
        /* 7个元素居中 */
        margin: 10px calc((100% - 20px * 7) / 7 / 2);
      }
      .box:nth-of-type(3n + 1) {
        background-color: red;
      }
      .box:nth-of-type(3n + 2) {
        background-color: green;
      }
      .box:nth-of-type(3n + 3) {
        background-color: yellow;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
    </div>
  </body>
</html>
